home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 349_01 / sss.arc / EX_0401.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-09  |  1.2 KB  |  73 lines

  1. /* Program EX_0401.C
  2.    Listing 6C - see documentation in TUTOR.SSS
  3. */
  4.  
  5. #include "SSSC.H"
  6.  
  7. #define  ARRIVL   1
  8. #define  TRYBUY   2
  9. #define  REPLNS   3
  10.  
  11. #define  CUSTMR   0
  12. #define  GOODS    1
  13.  
  14. int c, ecode;
  15.  
  16. void prime(void)
  17. {
  18.   INIQUE(0, 0, 2);
  19.   INISTA(1, "Out of stock", 0, 0, 0.0, 0.0);
  20.   INISTA(2, "Ave stock", 1, 0, 0.0, 0.0);
  21.   SIMEND(40.0);
  22.   CREATE(EX(2.0), 0);
  23.   c = 15;
  24.   TALLY(2, c);
  25. }
  26.  
  27. void buying()
  28. {
  29.   if (c == 4) CREATE(TR(5.0, 7.0, 9.0), GOODS);
  30.   if (c >  0) c--; else TALLY(1, 1.0);
  31.   TALLY(2, c);
  32.   DISPOS();
  33. }
  34.  
  35. void order(void)
  36. {
  37.   c += 12;
  38.   TALLY(2, c);
  39.   DISPOS();
  40. }
  41.  
  42. main()
  43. {
  44.   prime();
  45.  
  46.   do
  47.   {
  48.     if ((ecode = NEXTEV()) > 0)
  49.     switch (ecode)
  50.     {
  51.       case ARRIVL:
  52.                 if (IDE() == CUSTMR)
  53.                 {
  54.                   CREATE(EX(2), 0);
  55.                   SCHED(0.0, TRYBUY, IDE());
  56.                 } else
  57.                   SCHED(0.0, REPLNS, IDE());
  58.                 break;
  59.  
  60.       case TRYBUY:
  61.                 buying();
  62.                 break;
  63.  
  64.       case REPLNS:
  65.                 order();
  66.                 break;
  67.     }
  68.   } while(ecode);
  69.  
  70.   SUMRY("");
  71.  
  72. }
  73.